const targets = ['packages', 'internal', 'apps', 'demos', 'modules']

module.exports = function (plop) {
  plop.setGenerator('library', {
    description: 'Adds a new library to devcreafter',
    prompts: [
      {
        type: 'input',
        name: 'name',
        message: 'library package name',
        default: 'library-name',
        validate: (name) => {
          if (/\s/g.test(name))
            throw new Error('Name can\'t have spaces')

          return true
        },
        transformer: name => name.toLowerCase(),
      },
      {
        type: 'input',
        name: 'description',
        message: 'library description',
        default: 'devcreafter Package',
      },
      {
        type: 'list',
        name: 'pkgType',
        message: 'library target',
        choices: ['package', 'vue-library'],
        default: 'packages',
      },
      {
        type: 'list',
        name: 'target',
        message: 'library target',
        choices: targets,
        default: 'packages',
      },
    ],
    actions: [
      {
        type: 'addMany',
        destination: '{{target}}/{{name}}',
        base: 'internal/creator/library',
        templateFiles: 'internal/creator/library',
      },
    ],
  })
}
